<?php namespace Home\Controller; 


//确认购物车控制器
class ConfirmController extends CommonController{


	public function __init()
	{
		parent::__init();
	}
	

    public function index(){
    	if(!IS_POST){
    		View::error('请提交购车数据',U('Cart/index'));
    	}
//		p($_POST);die;
		
		$glid=Q('post.glid');
//		p($glid);die;
		$_SESSION['cartglid']=$glid;
//		p($_SESSION);die;

		$data=$this->getCartGoods($glid);
//		p($data);die;

		View::with('data',$data);
		View::make();
    }
	
	

	private function getCartGoods($glid){

		$data=Cart::getGoods(); 
//		p($glid);die;
//		p($data);die;
		
		$comData=array();
		
		$totalData=array();
		
		foreach($data as $k=>$v){

			if(in_array($k,$glid)){
				
				$comData['goods'][]=$v;

				$totalData[]=$v['total'];
				
			}
		}
//		p($totalData);

		$comData['total_all']=array_sum($totalData);
//		p($comData);die;
		return $comData;
	}
}
